﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SundayWishModel.Entities;
using NHibernate;

namespace SundayWishBLL
{
    public class PrivateDishHelper:DishHelper
    {
        public PrivateDishHelper()
        {
            this.DishPublic = 0;
        }

        public IList<Dish> GetDishByUser(int UserId)
        {
            ISession Session = NHibernateHelper.GetSession();
            UserHelper uh = new UserHelper();
            return uh.GetUser(UserId).Dishes;
        }

        public Boolean AddToPrivate(int DishId, int UserId)
        {
            ISession Session = NHibernateHelper.GetSession();
            Dish dish = Session.Get<Dish>(DishId);
            Dish newdish = new Dish();
            newdish.DishName = dish.DishName;
            newdish.DishStep = dish.DishStep;
            newdish.DishMaterial = dish.DishMaterial;
            newdish.DishKind = dish.DishKind;
            newdish.CreateDate = DateTime.Now;
            newdish.LastModifyDate = DateTime.Now;
            newdish.UserId = UserId;
            newdish.DishPublic = 0;
            Session.Save(newdish);
            Session.Flush();
            return true;
        }
    }
}
